#include <wx/gdicmn.h>
#include <wx/menu.h>
#include "ThreadSearchLoggerBase.h"
#include "ThreadSearchLoggerList.h"
#include "ThreadSearchLoggerTree.h"
#include "ThreadSearchView.h"
#include "ThreadSearchControlIds.h"
#include "ThreadSearch.h"

ThreadSearchLoggerBase* ThreadSearchLoggerBase::BuildThreadSearchLoggerBase( ThreadSearchView& threadSearchView,
    ThreadSearch& threadSearchPlugin, eLoggerTypes loggerType, InsertIndexManager::eFileSorting fileSorting,
    wxPanel* pParent,  long id ) {
  ThreadSearchLoggerBase* pLogger = NULL;
  if( loggerType == TypeList ) {
    pLogger = new ThreadSearchLoggerList( threadSearchView, threadSearchPlugin, fileSorting, pParent, id );
  } else {
    pLogger = new ThreadSearchLoggerTree( threadSearchView, threadSearchPlugin, fileSorting, pParent, id );
  }
  return pLogger;
}

void ThreadSearchLoggerBase::Update() {
  Clear();
  m_IndexManager.SetFileSorting( m_ThreadSearchPlugin.GetFileSorting() );
}

void ThreadSearchLoggerBase::ShowMenu( const wxPoint& point ) {
  bool enable = !m_ThreadSearchView.IsSearchRunning();
  wxMenu menu( _T( "" ) );
  wxMenuItem* menuItem = menu.Append( controlIDs.Get( ControlIDs::idMenuCtxDeleteItem ), _T( "删除项目" ) );
  menuItem->Enable( enable );
  menuItem = menu.Append( controlIDs.Get( ControlIDs::idMenuCtxDeleteAllItems ), _T( "清空项目" ) );
  menuItem->Enable( enable );
  GetWindow()->PopupMenu( &menu, point );
}
